
import datetime
import random
import string
import logging


#生成唯一字符串
def uuid_maker(n):
    return '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now()) + ''.join(
        [str(random.randint(1, 10)) for i in range(n - 20)])



# 生成8位随机字符串
def randomStr(n):
    return ''.join(random.sample(string.ascii_letters + string.digits, n))


# 生成日期字符串
def timeStr():
    return datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    #return datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")
    #return datetime.datetime.now().strftime("%Y-%m-%d  %H:%M:%S  %f")

def ReadTxtName(rootdir):
    lines = []
    with open(rootdir, 'r',encoding='UTF-8') as f:
        while True:
            line = f.readline()
            if not line:
                break
            line = line.strip('\n')
            lines.append(line)
    return lines

programNamelist = ReadTxtName('data/program.txt')
seriesNamelist = ReadTxtName('data/series.txt')
categoryNamelist = ReadTxtName('data/category.txt')
packageNamelist = ReadTxtName('data/package.txt')
programcategorylist = ReadTxtName('data/programcategory.txt')
seriescategorylist = ReadTxtName('data/seriescategory.txt')
directorlist = ReadTxtName('data/director.txt')
actorlist = ReadTxtName('data/actor.txt')

def mapping(file):
    map = {}
    with open(file, "r",encoding='UTF-8') as f:
        for line in f.readlines():
            line = line.strip("\n")
            b = line.split(",")
            map[b[0]] = b[1]
    return map

def writelog(filename):
    LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
    logging.basicConfig(filename=filename, level=logging.DEBUG, format=LOG_FORMAT, filemode='w')
    # 定义一个Handler打印INFO及以上级别的日志到sys.stderr
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    # 设置日志打印格式
    #formatter = logging.Formatter('%(asctime)-12s: %(levelname)-8s %(message)s')
    formatter = logging.Formatter(LOG_FORMAT)
    console.setFormatter(formatter)
    # 将定义好的console日志handler添加到root logger
    logging.getLogger('').addHandler(console)


if __name__ == '__main__':

    print(uuid_maker(25))
    print(randomStr(25))
